package org.semanticflash.rdf.io.ntriple
{
	
	
	import org.semanticflash.rdf.triple.RDFTriple;
	import org.semanticflash.rdf.utils.AbstractRDFTest;
	import org.semanticflash.rdf.values.IRI;
	import org.semanticflash.rdf.values.RDFLangLiteral;
	import org.semanticflash.rdf.values.RDFPlainLiteral;
	import org.semanticflash.rdf.values.RDFTypedLiteral;
	import org.semanticflash.rdf.vocab.Vxsd;



	/**
	 * 
	 * TODO: negative parser tests
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */
	public class NTripleParser2Test extends AbstractRDFTest
	{
		
		
		public function test_parseIRI( ):void
		{
			assertEquals( 
				NTripleParser2.parseIRI( "<http://foo.bar/k#ff>"  ) , 
				IRI.instance( "http://foo.bar/k#ff" )  
			);
				
		}
		
		
		
		
		public function test_parseLiteral( ):void
		{
		
		
			assertEquals(  
				NTripleParser2.parseLiteral( '"plain literal"' ) ,
				RDFPlainLiteral.instance( "plain literal" )
			);		
		

			assertEquals(  
				NTripleParser2.parseLiteral( '"67"^^<http://www.w3.org/2000/10/XMLSchema-datatypes#int>' ) ,
				RDFTypedLiteral.instance( "67", Vxsd._int )
			);		


			assertEquals(  
				NTripleParser2.parseLiteral( '"haha"@en' ) ,
				RDFLangLiteral.instance( "haha", "en" )
			);




			// backslashes

			assertEquals(  
				NTripleParser2.parseLiteral( '"  \\\\  "' ) ,
				RDFPlainLiteral.instance( "  \\  " )
			);
			
			
			assertEquals(  
				NTripleParser2.parseLiteral( '"  \\"  "' ) ,
				RDFPlainLiteral.instance( '  "  ' )
			);


			assertEquals(  
				NTripleParser2.parseLiteral( '"D\\u00FCrst"' ) ,
				RDFPlainLiteral.instance( 'Dürst' )
			);
			


			assertEquals(  
				NTripleParser2.parseLiteral( '"line\\' + 'n' + 'break"' ) ,
				RDFPlainLiteral.instance( "line\nbreak" )
			);





		
		}
		
		
		
		public function test_parseTriple( ):void
		{
			
			var t:RDFTriple;
			
			t = NTripleParser2.parseTriple( '_:7897 <http://foo.com/bar> "plain literal"' );
		
			assertTrue( (t.s as IRI).isBNode );
			assertEquals( t.p , IRI.instance( "http://foo.com/bar" ) );		
			assertEquals( t.o , RDFPlainLiteral.instance( "plain literal" ) );
		
		
		}
		
		
		
		
		
		
	}
	
}